package dao;

import java.util.List;

import javax.sql.DataSource;

import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import mapper.UserMapper;
import model.Goods;
import model.User;

public class UserDaoImpl implements UserDao {

	private DataSource dataSource;
	private JdbcTemplate jdbcTemplateObject;

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
		this.jdbcTemplateObject = new JdbcTemplate(dataSource);
	}

	public User loginUser(String account, String passwd) {
		User user = null;
		try{
			String SQL = "select account, password from user where account=? and password=?";
			user = (User) jdbcTemplateObject.queryForObject(SQL, new Object[]{account,passwd}, (RowMapper<User>) new UserMapper());
			System.out.println("Created Record Name = " + account + " password = " + passwd);
		}catch(Exception ex){
			// TODO: handle exception
		}
		return user;
	}
	
//	@Test
//	public void testLogin(){
//		login("11","22");
//	}
 
	public void insert(Goods goods) {
		// TODO Auto-generated method stub

	}

	public Goods getgoods(Integer gid) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Goods> listgoods() {
		// TODO Auto-generated method stub
		return null;
	}

	public void delete(Integer id) {
		// TODO Auto-generated method stub

	}

	public void update(Goods goods) {
		// TODO Auto-generated method stub

	}

	public void create() {
		// TODO Auto-generated method stub

	}

}
